package com.ruoyi.web.controller.gas;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gas.domain.GasDetectionObjectDict;
import com.ruoyi.gas.service.IGasDetectionObjectDictService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测对象字典Controller
 *
 * @author ruoyi
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/gas/objectDict")
public class GasDetectionObjectDictController extends BaseController
{
    @Autowired
    private IGasDetectionObjectDictService gasDetectionObjectDictService;

    /**
     * 查询检测对象字典列表
     */
    @PreAuthorize("@ss.hasPermi('gas:objectDict:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasDetectionObjectDict gasDetectionObjectDict)
    {
        startPage();
        List<GasDetectionObjectDict> list = gasDetectionObjectDictService.selectGasDetectionObjectDictList(gasDetectionObjectDict);
        return getDataTable(list);
    }

    /**
     * 导出检测对象字典列表
     */
    @PreAuthorize("@ss.hasPermi('gas:objectDict:export')")
    @Log(title = "检测对象字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasDetectionObjectDict gasDetectionObjectDict)
    {
        List<GasDetectionObjectDict> list = gasDetectionObjectDictService.selectGasDetectionObjectDictList(gasDetectionObjectDict);
        ExcelUtil<GasDetectionObjectDict> util = new ExcelUtil<GasDetectionObjectDict>(GasDetectionObjectDict.class);
        util.exportExcel(response, list, "检测对象字典数据");
    }

    /**
     * 获取检测对象字典详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gas:objectDict:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") Long code)
    {
        return success(gasDetectionObjectDictService.selectGasDetectionObjectDictByCode(code));
    }

    /**
     * 新增检测对象字典
     */
    @PreAuthorize("@ss.hasPermi('gas:objectDict:add')")
    @Log(title = "检测对象字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasDetectionObjectDict gasDetectionObjectDict)
    {
        return toAjax(gasDetectionObjectDictService.insertGasDetectionObjectDict(gasDetectionObjectDict));
    }

    /**
     * 修改检测对象字典
     */
    @PreAuthorize("@ss.hasPermi('gas:objectDict:edit')")
    @Log(title = "检测对象字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasDetectionObjectDict gasDetectionObjectDict)
    {
        return toAjax(gasDetectionObjectDictService.updateGasDetectionObjectDict(gasDetectionObjectDict));
    }

    /**
     * 删除检测对象字典
     */
    @PreAuthorize("@ss.hasPermi('gas:objectDict:remove')")
    @Log(title = "检测对象字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable Long[] codes)
    {
        return toAjax(gasDetectionObjectDictService.deleteGasDetectionObjectDictByCodes(codes));
    }
}
